clear all
clear matrix
version 13
capture log close
set more off, permanently

*-------------------------------------------------------------------------------
* Options	
*-------------------------------------------------------------------------------

	* For Heiko:
	global main		= "\\iab.baintern.de\DFS\017\Ablagen\D01700-Data\N2066017\Datenaustausch\GradAB\Schnitzlein_Stueber\Stueber\CADAL_Flow_Dataset\Federica"
	global data_orig= "N:\Ablagen\D01700-IAB-Projekte\D01700-CADAL_Flow_Dataset\package"
	global data_proc= "$main"+"\"+"temp"
	global log   	= "$main"+"\"+"log"
	global do		= "$main"+"\"+"do"
	global data_add = "$main"+"\"+"data"
	global r="Heiko"


*-------------------------------------------------------------------------------
cd "$main"
*-------------------------------------------------------------------------------

log using "$log/getmaxshare", text replace
use "$data_proc\data_federica_1990_2014_west.dta", clear 

gen quarter = q - 4 * (a - 1)
rename st_reg employment
replace employment = employment/1
drop if employment==.|employment==0

gen count_all = 1
gen count_new = 0
replace count_new = 1 if q == founded_q

gen eventdate=yq(year,quarter)
format eventdate %tq
drop quarter

ren district krs
merge m:1 krs using "$data_add/amr_krs_72.dta"
drop if _merge!=3
drop _merge

rename w93_imp w93_3
drop if w93_3>=750 & w93_3<900	
drop if w93_3<150
drop if year > 2004
drop year 

by amr eventdate, sort: egen maxemployment = max(employment)
by amr eventdate, sort: egen totemployment = total(employment)
by amr eventdate, sort: gen totcount = _N 

keep amr eventdate maxemployment totemployment totcount
duplicates drop
saveold "$data_proc/tocalibrateS.dta", replace version(14)

clear 
log close
********************************************************************************
